package com.jzhao.gper.spring.v3.aop.aspect;

import com.jzhao.gper.spring.v3.aop.intercept.JZJoinPoint;
import com.jzhao.gper.spring.v3.aop.intercept.JZMethodInterceptor;
import com.jzhao.gper.spring.v3.aop.intercept.JZMethodInvocation;

import java.lang.reflect.Method;

/**
 * @author jzhao
 * @date 2020/4/21 9:32
 */
public class JZAspectJAfterThrowingAdvice extends JZAbstractAspectJAdvice implements JZMethodInterceptor {

    private JZJoinPoint jp;

    public JZAspectJAfterThrowingAdvice(Object aspect, Method adviceMethod) {
        super(aspect, adviceMethod);
    }

    protected Object afterReturning(JZJoinPoint jp,  Object returnValue, Throwable ex)
            throws Throwable {

        return invokeAdviceMethod(jp, returnValue, ex);
    }

    @Override
    public Object invoke(JZMethodInvocation mi) throws Throwable {
        try {
            return mi.proceed();
        }
        catch (Throwable ex) {
            afterReturning(mi,null,ex);
            throw ex;
        }
    }
}
